package net.badcurrent.ldapodm;

import java.util.List;

/**
 * <code>Session</code> is the main user interface of interaction to LDAP-ORM. Its instances
 * are not thread safe.
 */
public interface Session  {
    /**
     * Load an object from the directory by its DN.
     * @param distinguishedName
     * @param mappedClass
     * @return the mapped object, null if the object does not exist
     */
    Object load(String distinguishedName, Class mappedClass);

    /**
     * Query the directory for instances of the mappedClass that match
     * the queryString.
     * @param queryString an LDAP search filter
     * @param mappedClass
     * @return a <code>List</code> of matching objects.
     */
    List find(String queryString, Class mappedClass);

    /**
     * Detach the supplied object from the <code>Session.</code>  This removes
     * the object from the identity map (cache) but does not trigger it from
     * removal from the directory.
     * @param o
     */
    void detach(Object o);

    /**
     * Write all changes (additions, modifications and deletions) to the directory.
     */
    void flush();

    /**
     * Mark the supplied object to be saved upon the next invocation of flush().
     * @param o
     */
    void save(Object o);

    /**
     * Determine if the supplied object is associated with the <code>Session</code>.
     * @param o
     * @return true if the object is attached, false if not.
     */
    boolean isObjectAttached(Object o);

}
